package com.example.demo.utils;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;

/**
 * @author Lucy
 * @create 2024-02-02 20:26
 */
public class SMSUtil {
    /**
     * 发送短信
     * //@param signName 签名
     * //@param templateCode 模板
     * @param phoneNumbers 手机号
     * @param param 参数
     */
    public static void sendCode(String phoneNumbers,String param) {
        //TODO 改成自己的
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI5tJCEjEWeTtk8ba8Eshz", "NkrCvlj2zZdn5TYxIXWUBPSYPHEwoI");
        IAcsClient client = new DefaultAcsClient(profile);

        SendSmsRequest request = new SendSmsRequest();
        request.setSysRegionId("cn-hangzhou");
        request.setPhoneNumbers(phoneNumbers);
        request.setSignName("新苗同学");
        request.setTemplateCode("SMS_465135507");
        request.setTemplateParam("{\"code\":\"" + param + "\"}");
        try {
            SendSmsResponse response = client.getAcsResponse(request);
            System.out.println("短信发送成功");
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}
